home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / client / trans / checkTransState.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.0 KB  |  251 lines

  1. /*
  2.  *   $RCSfile: checkTransState.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:30 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "pool.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "serverinfo.h"
  51. #include "sm_state.h"
  52. #include "volume.h"
  53. #include "io_extfuncs.h"
  54. #include "trans_funcs.h"
  55. #include "msg_funcs.h"
  56. #include "sm_globals.h"
  57. #include "trans_globals.h"
  58.  
  59.  
  60.  TID*
  61. getLocalTid()
  62. {
  63.     return &(TransRec.clientTid);
  64. }
  65.  
  66.  int
  67. checkLocalTransState ()
  68. {
  69.     TRANSREC        *transRec;
  70.  
  71.     TRPRINT(TR_TRANS, TR_LEVEL_1, ("client state %d",
  72.                     TransRec.clientTransState));
  73.  
  74.     transRec = findTransRec(getLocalTid());
  75.  
  76.     transRec->abortIfError = FALSE;
  77.     /* we reset this regardless of the state because
  78.      * we don't want the FAIL macro in the caller
  79.      * to try to abort the tx if, say, we
  80.      * were in an illegitimate state
  81.      */
  82.  
  83.     switch (transRec->clientTransState) {
  84.     case T_ACTIVE:
  85.         TRPRINT(TR_TRANS, TR_LEVEL_1, ("checkLocalTransState-OK"));
  86.         return esmNOERROR;
  87.  
  88.     case T_ABORT:
  89.         SM_ERROR(TYPE_USER, esmTRANSABORTED);
  90.         break;
  91.  
  92.     case T_INACTIVE:
  93.         SM_ERROR(TYPE_USER, esmNOACTIVETRANS);
  94.         break;
  95.  
  96.     case T_PREPARED:
  97.         SM_ERROR(TYPE_USER, esmTRANSPREPARED);
  98.         break;
  99.  
  100.     default:
  101.         /* internal error: the only states that a tx can
  102.          * have on the client side are T_ACTIVE, T_INACTIVE, T_PREPARED, and T_ABORT 
  103.          */
  104.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  105.         break;
  106.     }
  107.     TRPRINT(TR_TRANS, TR_LEVEL_1, ("checkLocalTransState-FAILURE"));
  108.     return esmFAILURE;
  109. }
  110.  
  111.  TID *
  112. getServerTid (
  113.     SERVERINFO    *serverInfo,
  114.     VOLID         volid,
  115.     TRANSREC     *transRec
  116. )
  117. {
  118.     SERVERTRANSREC     *st;
  119.  
  120.     if(serverInfo == NULL) {
  121.         VOLREC        *volRec;
  122.  
  123.         SM_ASSERT(LEVEL_1, (volid != NULLVOLID));
  124.  
  125.         volRec = io_FindVolId(volid);
  126.  
  127.         SM_ASSERT(LEVEL_1, (volRec != NULL));
  128.         SM_ASSERT(LEVEL_1, (volRec->serverInfo != NULL));
  129.         serverInfo = volRec->serverInfo;
  130.  
  131.     }
  132.  
  133.     TRPRINT(TR_TRANS, TR_LEVEL_1, 
  134.         ("searching for server in participants"));
  135.     for (st = (SERVERTRANSREC *)
  136.         FIRST_LIST_ELEMENT(&(transRec->participants));
  137.         (st != NULL) && (st->serverInfo != serverInfo);
  138.         st = (SERVERTRANSREC *)NEXT_LIST_ELEMENT(&(st->participants)) 
  139.         ) ;
  140.  
  141.     if(st == NULL) {
  142.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  143.     }
  144.     if( (st->serverTransState != T_ACTIVE) &&
  145.         (st->serverTransState != T_PREPARED)) {
  146.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  147.     }
  148.  
  149.     return &(st->tid);
  150. }
  151.  
  152.  int
  153. checkTransState (
  154.     VOLID volid
  155. )
  156. {
  157.     SERVERTRANSREC     *st;
  158.     VOLREC            *volRec;
  159.  
  160.  
  161.     if( checkLocalTransState() != esmNOERROR) {
  162.         return esmFAILURE;
  163.     }
  164.     TRPRINT(TR_TRANS, TR_LEVEL_1, ("checkTransState volid %d", volid));
  165.  
  166.     /*
  167.      * see if we know about this volume
  168.      */
  169.     volRec = io_FindVolId(volid);
  170.     if(volRec == NULL) {
  171.         TRPRINT(TR_TRANS, TR_LEVEL_1, ("volume for volid %d NOT found",volid));
  172.         return esmFAILURE;
  173.     }
  174.  
  175.     if((SM_State.serverInfo = volRec->serverInfo) == NULL) {
  176.         TRPRINT(TR_TRANS, TR_LEVEL_1, ("server for volid %d NOT found",volid));
  177.         return esmFAILURE;
  178.     }
  179.     TRPRINT(TR_TRANS, TR_LEVEL_1, ("server for volid %d found",volid));
  180.  
  181.     SM_State.logInfo = &(SM_State.serverInfo->logInfo);
  182.     SM_State.logLevel =  
  183.         (volRec->properties & VOL_TEMP)? LOG_NONE: SM_State.defaultLogLevel;
  184.  
  185.     TRPRINT(TR_TRANS, TR_LEVEL_1, 
  186.         ("searching for server in participants"));
  187.     for (st = (SERVERTRANSREC *)
  188.         FIRST_LIST_ELEMENT(&(TransRec.participants));
  189.         (st != NULL) && (st->serverInfo != volRec->serverInfo);
  190.         st = (SERVERTRANSREC *)NEXT_LIST_ELEMENT(&(st->participants)) 
  191.         ) ;
  192.  
  193.     if(st == NULL) {
  194.         /* should have been added by verifyServer() */
  195.         SM_ERROR(TYPE_FATAL, esmINTERNAL);
  196.     }
  197.     /*
  198.      * what is the remote server's tx state?
  199.      */
  200.     switch( st->serverTransState ) {
  201.     case T_ACTIVE:
  202.         TRPRINT(TR_TRANS, TR_LEVEL_1, ("checkTransState(volid %d)-OK", volid));
  203.         SM_State.serverTid = st->tid; /* temp kludge */
  204.         break;
  205.  
  206.     case T_ABORT:
  207.         SM_ERROR(TYPE_USER, esmTRANSABORTED);
  208.         return esmFAILURE;
  209.  
  210.     case T_INACTIVE:
  211.         /* really, we should not get here */
  212.         SM_ERROR(TYPE_USER, esmNOACTIVETRANS);
  213.         break;
  214.  
  215.     case T_PREPARED:
  216.         SM_ERROR(TYPE_USER, esmTRANSPREPARED);
  217.         break;
  218.  
  219.     default:
  220.         SM_ERROR(TYPE_USER, esmINTERNAL);
  221.         return esmFAILURE;
  222.     }
  223.     return esmNOERROR;
  224. }
  225.  
  226.  int
  227. checkVolumeState (
  228.     VOLID volid
  229. )
  230. {
  231.     VOLREC            *volRec;
  232.  
  233.     volRec = io_FindVolId(volid);
  234.     if(volRec == NULL) {
  235.         TRPRINT(TR_TRANS, TR_LEVEL_1, ("volume for volid %d NOT found",volid));
  236.         return esmFAILURE;
  237.     }
  238.  
  239.     if((SM_State.serverInfo = volRec->serverInfo) == NULL) {
  240.         TRPRINT(TR_TRANS, TR_LEVEL_1, ("server for volid %d NOT found",volid));
  241.         return esmFAILURE;
  242.     }
  243.     TRPRINT(TR_TRANS, TR_LEVEL_1, ("server for volid %d found",volid));
  244.  
  245.     SM_State.logInfo = &(SM_State.serverInfo->logInfo);
  246.     SM_State.logLevel = SM_State.defaultLogLevel;
  247.  
  248.     return esmNOERROR;
  249. }
  250.  
  251.